import os
import glob

execfile('keplerian_mask.py', globals())



 ### H218O - standard params
v_src=4.25e3

inc=38.3
PA=32.0
mstar=1.285
dist=400.0
nbeams=0.65
r_min=0.10
r_max=0.3
zr=0.4
dV0=350.0
dVq=0.0

os.system('rm -rf V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask.image V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-h218o.image')
make_mask(image='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0) 
os.system('mv V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask.image V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-h218o.image')
exportfits(imagename='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-h218o.image',fitsimage='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-h218o.fits',overwrite=True)

## 225 GHz transition
os.system('rm -rf V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-hdo.image')
make_mask(image='V883_Ori_SB_HDO-225.535GHz_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0) 
os.system('mv V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask.image V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-hdo.image')

exportfits(imagename='V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-hdo.image',fitsimage='V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-hdo.fits',overwrite=True)

os.system('rm -rf V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-hdo.image')

#241 GHz
make_mask(image='V883_Ori_SB_HDO-241.558GHz_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0) 
os.system('mv V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask.image V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-hdo.image')


exportfits(imagename='V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-hdo.image',fitsimage='V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-hdo.fits',overwrite=True)


#Acetaldehyde CH3CHO
nu_hdo=241.56155e9
nu_ch3cho=241.56299e9
nu_ch3cho=241.56322770e9
v_shift=(nu_ch3cho- nu_hdo)/nu_hdo*3.0e8
v_src_shift=v_src-v_shift

#v_src_shift=1.55e3+4.1e3


os.system('rm -rf V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-ch3cho.image')

make_mask(image='V883_Ori_SB_HDO-241.558GHz_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src_shift,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr) 
os.system('mv V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask.image V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-ch3cho.image')

exportfits(imagename='V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-ch3cho.image',fitsimage='V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-ch3cho.fits',overwrite=True)



#Acetic Acid CH3COOH
nu_hdo=241.56155e9
nu_ch3cooh=241.56383270e9
v_shift=(nu_ch3cooh- nu_hdo)/nu_hdo*3.0e8
v_src_shift=v_src-v_shift


os.system('rm -rf V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-ch3cooh.image')

make_mask(image='V883_Ori_SB_HDO-241.558GHz_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src_shift,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr) 
os.system('mv V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask.image V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-ch3cooh.image')

exportfits(imagename='V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-ch3cooh.image',fitsimage='V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-ch3cooh.fits',overwrite=True)


#CH3OHCO
nu_hdo=225.89672e9
nu_ch3ocho=225.90074e9
v_shift=(nu_ch3ocho- nu_hdo)/nu_hdo*3.0e8
v_src_shift=v_src-v_shift

os.system('rm -rf V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-ch3ocho.image')
make_mask(image='V883_Ori_SB_HDO-225.535GHz_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src_shift,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr) 
os.system('mv V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask.image V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-ch3ocho.image')

exportfits(imagename='V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-ch3ocho.image',fitsimage='V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-ch3ocho.fits',overwrite=True)


 ### CH3OCH3 red
v_src=4.25e3+7.0e3


os.system('rm -rf V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask.image V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-h218o.image')
## 225 GHz transition
make_mask(image='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr) 
os.system('mv V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask.image V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_red.image')
exportfits(imagename='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_red.image',fitsimage='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_red.fits',overwrite=True)


 ### CH3OCH3 blue 2
v_src=4.25e3-5.76e3

os.system('rm -rf V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask.image V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_blue2.image')
## 225 GHz transition
make_mask(image='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr) 
os.system('mv V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask.image V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_blue2.image')
exportfits(imagename='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_blue2.image',fitsimage='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_blue2.fits',overwrite=True)

 ### CH3OCH3 blue
v_src=4.25e3-3.8e3

os.system('rm -rf V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask.image V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_blue.image')
## 225 GHz transition
make_mask(image='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr) 
os.system('mv V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask.image V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_blue.image')
exportfits(imagename='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_blue.image',fitsimage='V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-ch3och3_blue.fits',overwrite=True)

#### CH3OH
nbeams=1.0
r_max=0.4
v_src=-50.417e3
line='241.887'

os.system('rm -rf V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image')

make_mask(image='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0,dVq=dVq) 
os.system('mv V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask.image/ V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image')
exportfits(imagename='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image',fitsimage='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.fits',overwrite=True)

v_src=-39.688e3
line='241.879'
os.system('rm -rf V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image')

make_mask(image='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0,dVq=dVq) 
os.system('mv V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask.image/ V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image')
exportfits(imagename='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image',fitsimage='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.fits',overwrite=True)



v_src=-6.535e3
line='241.852'
os.system('rm -rf V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image')

make_mask(image='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0,dVq=dVq) 
os.system('mv V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask.image/ V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image')
exportfits(imagename='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image',fitsimage='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.fits',overwrite=True)


v_src=41.89e3
line='241.813'
os.system('rm -rf V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image')

make_mask(image='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0,dVq=dVq) 
os.system('mv V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask.image/ V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image')
exportfits(imagename='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image',fitsimage='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.fits',overwrite=True)


v_src=50.24e3
line='241.806'
os.system('rm -rf V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image')

make_mask(image='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0,dVq=dVq) 
os.system('mv V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask.image/ V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image')
exportfits(imagename='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.image',fitsimage='V883_Ori_SB_CH3OH-241.846GHz-fullcube_robust_2.0.mask-ch3oh-'+line+'.fits',overwrite=True)

#### C17O

v_src=4.25e3

inc=38.3
PA=32.0
mstar=1.285
dist=400.0
nbeams=1.25
r_min=0.05
r_max=0.85
zr=0.2
dV0=1200.0
dVq=0.0

os.system('rm -rf V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o.image')

make_mask(image='V883_Ori_SB_C17O-224.711GHz_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0,dVq=dVq) 
os.system('mv V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask.image V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o.image')

exportfits(imagename='V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o.image',fitsimage='V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o.fits',overwrite=True)

v_src=4.6e3
os.system('rm -rf V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o-4.6.image')

make_mask(image='V883_Ori_SB_C17O-224.711GHz_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0,dVq=dVq) 
os.system('mv V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask.image V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o-4.6.image')

v_src=3.7e3
os.system('rm -rf V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o-3.7.image')

make_mask(image='V883_Ori_SB_C17O-224.711GHz_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0,dVq=dVq) 
os.system('mv V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask.image V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o-3.7.image')

os.system('rm -rf V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o-3.7-4.6.image')
immath(imagename=['V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o-3.7.image','V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o-4.6.image'],
expr='iif(IM0==1,1.0,IM1)',outfile='V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o-3.7-4.6.image')

exportfits(imagename='V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o-3.7-4.6.image',fitsimage='V883_Ori_SB_C17O-224.711GHz_robust_2.0.mask-c17o-3.7-4.6.fits',overwrite=True)

#### H2CO

v_src=4.25e3

inc=38.3
PA=32.0
mstar=1.285
dist=400.0
nbeams=1.75
r_min=0.05
r_max=0.9
zr=0.2
dV0=1000.0
dVq=0.0

os.system('rm -rf V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co.image')

make_mask(image='V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr,dV0=dV0,dVq=dVq) 
os.system('mv V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask.image/ V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co.image')

exportfits(imagename='V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co.image',fitsimage='V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co.fits',overwrite=True)

v_src=4.6e3
os.system('rm -rf V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co-4.6.image')
make_mask(image='V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr) 
os.system('mv V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask.image/ V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co-4.6.image')


v_src=4.0e3
os.system('rm -rf V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co-4.0.image')
make_mask(image='V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.image',\
          inc=inc,PA=PA,mstar=mstar,dist=dist,vlsr=v_src,nbeams=nbeams,\
          r_min=r_min,r_max=r_max,zr=zr) 
os.system('mv V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask.image/ V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co-4.0.image')


os.system('rm -rf V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co-4.0-4.6.image')
immath(imagename=['V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co-4.0.image','V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co-4.6.image'],
expr='iif(IM0==1,1.0,IM1)',outfile='V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co-4.0-4.6.image')

exportfits(imagename='V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co-4.0-4.6.image',fitsimage='V883_Ori_SB_H2CO-225.694GHz-fullcube_robust_2.0.mask-h2co-4.0-4.6.fits',overwrite=True)


